package analysis.ProfessionalSchoolPlan;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ProfessionalSchoolPlanMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split(" ");
        String ProfessionalCode = words[5]; //专业代码
        int num = Integer.parseInt(words[7]);   // 招生人数
        // 跳过专业代码为0的行（在数据预处理阶段将null用0填充了，分析时不需要考虑这些数据）
        if (!ProfessionalCode.equals("0"))  // equals函数的参数需用“”
            context.write(new Text(ProfessionalCode), new IntWritable(num));
    }
}
